//
//  ConnectModel.m
//  UI15图片封装\
//
//  Created by dllo on 15/5/7.
//  Copyright (c) 2015年 蓝鸥. All rights reserved.
//

#import "ConnectModel.h"

@implementation ConnectModel

+ (void)connectUrlWith:(NSString *)url delegate:(id<ConnectModelDelegate>)delegate
{
    ConnectModel * model = [[ConnectModel alloc] init];
    [model createConnect:url];
    model.delegate = delegate;
    
    [model release];
}


- (void)createConnect:(NSString *)str
{
    NSURL * url = [NSURL URLWithString:str];
    
    NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
    
    [request setHTTPMethod:@"GET"];
    
    [NSURLConnection connectionWithRequest:request delegate:self];
    
    [request release];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    self.receiveData = [NSMutableData data];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [self.receiveData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [self.delegate sendData:_receiveData];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
}

@end
